﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace FlickrMe.shortcut
{
    /*
     * Shorcut Resovler for use on Microsoft OS. 
     * Resolves .lnk pathnames to actual path.
     */
    class LnkShortcutResolver : ShortcutResolver
    {
        public String resolvePath(String path)
        {
            // Shorcut is resolved via the windows scripting shell
            // The IWshRuntimeLibrary must be added as a reference in VS.

            IWshRuntimeLibrary.IWshShell shell = new IWshRuntimeLibrary.WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = 
                    (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path);

            return shortcut.TargetPath;

            
        }

        /*
         * Determines id the path name is shortcut.
         * ie. does it end with a .lnk extension.
         */
        public bool isShortcut(String path)
        {
            FileSystemInfo fi = new FileInfo(path);
    
            String ext = fi.Extension.ToLower();
            if (ext.Equals(".lnk")) return true;

            return false;
        }
    }
}
